package com.mapper;

import com.pojo.Admin;
import com.pojo.Notice;
import com.pojo.Student;
import com.pojo.Teacher;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NoticeMapper {

    @Insert("insert into notice(sender, type, title, conents, annex, releaseTime) value (#{sender},#{type},#{title},#{conents},#{annex},Now())")
    void release(Integer sender,Integer type,String title,String conents,String annex);

    @Select("select * from notice order by releaseTime desc limit #{page},#{pagesize}")
    List<Notice> getAll(Integer page,Integer pagesize);

    @Select("select count(*) from notice")
    Integer countAll();

    @Select("select * from notice where sender = #{sender} and type = #{type} order by releaseTime desc limit #{page},#{pagesize}")
    List<Notice> getList(Integer sender,Integer type,Integer page,Integer pagesize);

    @Select("select count(*) from notice where sender = #{sender} and type = #{type}")
    Integer countList(Integer sender,Integer type);

    @Select("select * from teacher where id = #{id}")
    Teacher getTeacherById(Integer id);

    @Select("select * from admin where id = #{id}")
    Admin getAdminById(Integer id);

    @Select("select * from notice where id = #{id}")
    Notice getById(Integer id);

    @Delete("delete from notice where id = #{id}")
    void delNotice(Integer id);

    @Select("select * from student where open_id = #{open_id}")
    Student getStudentByOpenId(String open_id);

    @Select("select * from notice where type = 0 order by releaseTime desc limit #{page},#{pagesize}")
    List<Notice> getAdminNotice(Integer page,Integer pagesize);

    @Select("select * from notice where type = 1 and sender = #{teacher_id} order by releaseTime desc limit #{page},#{pagesize}")
    List<Notice> getTeacherNotice(Integer teacher_id,Integer page,Integer pagesize);

}
